home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / XLayerInfo / XLayerUtil.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  6KB  |  157 lines

  1. /*
  2.  * Copyright (c) 1993-94, Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  21.  */
  22. /* $Revision: 1.2 $ */
  23. #include <stdio.h>
  24. #include "XLayerUtil.h"
  25.  
  26. static Bool layersRead;
  27. static Atom overlayVisualsAtom;
  28. static OverlayInfo **overlayInfoPerScreen;
  29. static int *numOverlaysPerScreen;
  30.  
  31. XLayerVisualInfo *
  32. XGetLayerVisualInfo(display, lvinfo_mask, lvinfo_template, nitems_return)
  33.    Display *display;
  34.    long lvinfo_mask;
  35.    XLayerVisualInfo *lvinfo_template;
  36.    int *nitems_return;
  37. {
  38.    XVisualInfo *vinfo;
  39.    XLayerVisualInfo *layerInfo;
  40.    Window root;
  41.    Status status;
  42.    Atom actualType;
  43.    unsigned long sizeData, bytesLeft;
  44.    int actualFormat, numVisuals, numScreens, count, i, j;
  45.  
  46.    vinfo = XGetVisualInfo(display, lvinfo_mask&VisualAllMask,
  47.       &lvinfo_template->vinfo, nitems_return);
  48.    if(vinfo == NULL)
  49.       return NULL;
  50.    numVisuals = *nitems_return;
  51.    if(layersRead == False) {
  52.       overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True);
  53.       if(overlayVisualsAtom != None) {
  54.          numScreens = ScreenCount(display);
  55.          overlayInfoPerScreen = (OverlayInfo**) malloc(numScreens*sizeof(OverlayInfo*));
  56.          numOverlaysPerScreen = (int*) malloc(numScreens*sizeof(int));
  57.          if(overlayInfoPerScreen != NULL && numOverlaysPerScreen != NULL) {
  58.             for(i=0; i<numScreens; i++) {
  59.                root = RootWindow(display, i);
  60.                status = XGetWindowProperty(display, root, overlayVisualsAtom,
  61.                   0L, (long)10000, False, overlayVisualsAtom, &actualType, &actualFormat,
  62.                   &sizeData, &bytesLeft, (char**) &overlayInfoPerScreen[i]);
  63.                if(status!=Success || actualType!=overlayVisualsAtom ||
  64.                  actualFormat!=32 || sizeData<4)
  65.                   numOverlaysPerScreen[i] = 0;
  66.                else
  67.                   numOverlaysPerScreen[i] = sizeData / (sizeof(OverlayInfo)/4);
  68.             }
  69.             layersRead = True;
  70.          } else {
  71.             if(overlayInfoPerScreen != NULL) free(overlayInfoPerScreen);
  72.             if(numOverlaysPerScreen != NULL) free(numOverlaysPerScreen);
  73.          }
  74.       }
  75.    }
  76.    layerInfo = (XLayerVisualInfo*) malloc(numVisuals * sizeof(XLayerVisualInfo));
  77.    if(layerInfo == NULL) {
  78.       XFree(vinfo);
  79.       return NULL;
  80.    }
  81.    count = 0;
  82.    for(i=0; i<numVisuals; i++) {
  83.       XVisualInfo *pVinfo;
  84.       int screen;
  85.       OverlayInfo *overlayInfo;
  86.  
  87.       pVinfo = &vinfo[i];
  88.       screen = pVinfo->screen;
  89.       overlayInfo = NULL;
  90.       if(layersRead) {
  91.          for(j=0; j<numOverlaysPerScreen[screen]; j++)
  92.             if(pVinfo->visualid == overlayInfoPerScreen[screen][j].overlay_visual) {
  93.                overlayInfo = &overlayInfoPerScreen[screen][j];
  94.            break;
  95.             }
  96.       }
  97.       if(lvinfo_mask & VisualLayerMask)
  98.          if(overlayInfo == NULL) {
  99.             if(lvinfo_template->layer != 0) continue;
  100.          } else
  101.             if(lvinfo_template->layer != overlayInfo->layer) continue;
  102.       if(lvinfo_mask & VisualTransparentType)
  103.          if(overlayInfo == NULL) {
  104.             if(lvinfo_template->type != None) continue;
  105.          } else
  106.             if(lvinfo_template->type != overlayInfo->transparent_type) continue;
  107.       if(lvinfo_mask & VisualTransparentValue)
  108.          if(overlayInfo == NULL)
  109.             /* non-overlay visuals have no sense of TransparentValue */
  110.             continue;
  111.          else
  112.             if(lvinfo_template->value != overlayInfo->value) continue;
  113.       layerInfo[count].vinfo = *pVinfo;
  114.       if(overlayInfo == NULL) {
  115.          layerInfo[count].layer = 0;
  116.          layerInfo[count].type = None;
  117.          layerInfo[count].value = 0; /* meaningless */
  118.       } else {
  119.          layerInfo[count].layer = overlayInfo->layer;
  120.          layerInfo[count].type = overlayInfo->transparent_type;
  121.          layerInfo[count].value = overlayInfo->value;
  122.       }
  123.       count++;
  124.    }
  125.    XFree(vinfo);
  126.    *nitems_return = count;
  127.    if(count == 0) {
  128.       XFree(layerInfo);
  129.       return NULL;
  130.    } else
  131.       return layerInfo;
  132. }
  133.  
  134. Status
  135. XMatchLayerVisualInfo(display, screen, depth, class, layer, lvinfo_return)
  136. Display *display;
  137. int screen, depth, class, layer;
  138. XLayerVisualInfo *lvinfo_return;
  139. {
  140.    XLayerVisualInfo *lvinfo;
  141.    XLayerVisualInfo lvinfoTemplate;
  142.    int nitems;
  143.  
  144.    lvinfoTemplate.vinfo.screen = screen;
  145.    lvinfoTemplate.vinfo.depth = depth;
  146.    lvinfoTemplate.vinfo.class = class;
  147.    lvinfoTemplate.layer = layer;
  148.    lvinfo = XGetLayerVisualInfo(display,
  149.       VisualScreenMask|VisualDepthMask|VisualClassMask|VisualLayerMask,
  150.       &lvinfoTemplate, &nitems);
  151.    if(lvinfo != NULL && nitems > 0) {
  152.       *lvinfo_return = *lvinfo;
  153.       return 1;
  154.    } else
  155.       return 0;
  156. }
  157.